<?php
namespace MyTools;

class Tools
{

    public function getDate($timestamp, $type = 0)
    {
        $now  = time();
        $diff = $now - $timestamp;

        if ($diff / 86400 > 30) {
            return intval($diff / 86400) . '天';
        }
        //
        if ($diff <= 60) {
            return '刚刚';
        } elseif ($diff <= 3600) {
            return floor($diff / 60) . '分钟前';
        } elseif ($diff <= 86400) {
            return floor($diff / 3600) . '小时前';
        } elseif ($diff <= 2592000 || $type = 1) {
            return floor($diff / 86400) . '天前';
        } else {
            return '一个月前';
        }
    }

}
